import math
from dataclasses import dataclass
from typing import Optional

n = int(input())
mid = list(map(int, input().split()))
other = list(map(int, input().split()))

list1 = []


@dataclass()
class Node:
    val: int
    left: Optional['Node'] = None
    right: Optional['Node'] = None


def buildT(preO: list, inO: list):
    if len(preO) == 0:
        return None
    else:
        root = Node(val=preO[0])
        index = inO.index(preO[0])
        # 左子树
        root.left = buildT(preO[1:index + 1], inO=inO[:index])
        # 右子树,preO[index + 1:]
        root.right = buildT(preO[index + 1:], inO=inO[index + 1:])
        return root


def buildT_back(back0: list, inO: list):
    if len(back0) == 0:
        return None
    else:
        root = Node(back0[-1])
        index = inO.index(back0[-1])
        root.left = buildT_back(back0[:index], inO[:index])
        root.right = buildT_back(back0[index + 1:-1], inO[index + 1:])
        return root

math.factorial()
def bfs(root: Node):
    from collections import deque
    d = deque()
    d.append(root)
    while len(d) != 0:
        root = d.popleft()
        list1.append(root.val)
        if root.right:
            d.append(root.right)
        if root.left:
            d.append(root.left)


# def backorder(root):
#     if root is None: return
#     preorder(root.right)
#     preorder(root.left)
#     list1.append(root.val)
#
#
def preorder(root):
    if root is None: return
    list1.append(root.val)
    preorder(root.left)
    preorder(root.right)


tree = buildT(other, mid)
# preorder(tree)
bfs(tree)
print(*list1)